home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- /*
- * candraw -
- * Draw points, line, rectangles and texture maps onto a
- * canvas.
- *
- * Paul Haeberli - 1991
- *
- * exports
- *
- void drawaline(c,x,y)
- void drawscatter(c,x,y)
- void drawlongscatter(c,x,y)
- void drawmultiline(c,x,y)
-
- void mysincos(a,s,c)
- void setangle(a)
- void setangledelta(dx,dy)
- void setrectsize(dx,dy)
- void drawarect(c,x,y,tm)
- *
- */
- #include "math.h"
- #include "canvas.h"
- #include "texture.h"
-
- float flerp();
-
- #define ROTX(x,y) ((angc*(x))-(angs*(y)))
- #define ROTY(x,y) ((angs*(x))+(angc*(y)))
- #define MYTOLERANCE (0.01)
- static float angs, angc;
- static float xmin, xmax;
- static float ymin, ymax;
- static float *costab;
-
- void drawaline(c,x,y)
- canvas *c;
- float x, y;
- {
- float x1, y1, x2, y2;
-
- x1 = x+ROTX(xmin,0.0);
- y1 = y+ROTY(xmin,0.0);
- x2 = x+ROTX(xmax,0.0);
- y2 = y+ROTY(xmax,0.0);
- drawaaline(c,x1,y1,x2,y2);
- }
-
- void drawscatter(c,x,y)
- canvas *c;
- float x, y;
- {
- float dx, dy;
- float x1, y1;
- int i;
-
- for(i=0; i<12; i++) {
- getcircpos(&dx,&dy);
- x1 = x+xmax*dx;
- y1 = y+xmax*dy;
- drawapoint(c,x1,y1);
- }
- }
-
- void drawlongscatter(c,x,y)
- canvas *c;
- float x, y;
- {
- float dx, dy;
- float rx, ry, x1, y1;
- int i;
-
- dx = 2*xmax;
- dy = dx/15.0;
- for(i=0; i<12; i++) {
- rx = dx*qrand();
- ry = dy*qrand();
- x1 = x+ROTX(rx,ry);
- y1 = y+ROTY(rx,ry);
- drawapoint(c,x1,y1);
- }
- }
-
- void drawmultiline(c,x,y)
- canvas *c;
- float x, y;
- {
- float x1, y1, x2, y2, fy;
- float oxmin, oxmax;
- int i, nb;
-
- nb = ymax;
- if(nb<2)
- nb = 2;
- for(i=0; i<nb; i++) {
- oxmax = xmax*(1.0+0.4*qrand());
- oxmin = xmin*(1.0+0.2*qrand());
- fy = flerp(ymin,ymax,i/(nb-1.0));
- x1 = x+ROTX(oxmin,fy);
- y1 = y+ROTY(oxmin,fy);
- x2 = x+ROTX(oxmax,fy);
- y2 = y+ROTY(oxmax,fy);
- drawaaline(c,x1,y1,x2,y2);
- }
- }
-
- void mysincos(a,s,c)
- float a;
- float *s, *c;
- {
- int i;
-
- if(!costab) {
- costab = (float *)mymalloc(360*sizeof(float));
- for(i=0; i<360; i++)
- costab[i] = fcos((i*M_PI)/180.0);
- }
- while(a<0.0)
- a += 360.0;
- i = a;
- *c = costab[i%360];
- *s = costab[(i+270)%360];
- }
-
- /*
- * setangle -
- * set the angle for brush strokes.
- *
- */
- void setangle(a)
- float a;
- {
- mysincos(a,&angs,&angc);
- }
-
- /*
- * setangledelta -
- * use delx and dely to set the angle for brush strokes.
- *
- */
- void setangledelta(dx,dy)
- float dx, dy;
- {
- float mag;
-
- mag = fsqrt(dx*dx+dy*dy);
- if(mag>0.000001) {
- angc = dx/mag;
- angs = dy/mag;
- }
- }
-
- /*
- * setrectsize -
- * set the size of rectangles.
- *
- */
- void setrectsize(dx,dy)
- float dx,dy;
- {
- xmax = dx/2.0;
- ymax = dy/2.0;
- xmin = -xmax;
- ymin = -ymax;
- }
-
-
- /*
- * drawarect -
- * draw a rectangle at the specified position with the
- * current angle, rectsize, color and alpha
- *
- */
- void drawarect(c,x,y,tm)
- canvas *c;
- float x, y;
- TEXTURE *tm;
- {
- float pos[4][2];
- int i, smini, smaxi;
- float sminy, smaxy;
- float sminx, smaxx, d;
- vect tp, edgex, edgey;
-
- pos[0][0] = x+ROTX(xmin,ymin);
- pos[0][1] = y+ROTY(xmin,ymin);
- pos[1][0] = x+ROTX(xmax,ymin);
- pos[1][1] = y+ROTY(xmax,ymin);
- pos[2][0] = x+ROTX(xmax,ymax);
- pos[2][1] = y+ROTY(xmax,ymax);
- pos[3][0] = x+ROTX(xmin,ymax);
- pos[3][1] = y+ROTY(xmin,ymax);
- if(tm) {
- d = (tm->xsize-1.0-MYTOLERANCE)/(xmax-xmin);
- edgex.x = angc*d;
- edgex.y = angs*d;
- edgex.z = -(pos[0][0]*edgex.x+pos[0][1]*edgex.y);
- d = (tm->ysize-1.0-MYTOLERANCE)/(ymax-ymin);
- edgey.x = -angs*d;
- edgey.y = angc*d;
- edgey.z = -(pos[0][0]*edgey.x+pos[0][1]*edgey.y);
- cantm(tm,&edgex,&edgey);
- } else
- cantm(0,0,0);
- canbeginscan(c,1);
- for(i=0; i<4; i++)
- canvertex(pos[i][0],pos[i][1]);
- canendscan();
- }
-